import request from '@/config/axios'
import {ResourceContentVO} from "@/api/resource/content";
import {ResourceType} from "@/types/resource";

// 资源分组 VO
export interface ResourceGroupVO {
  id: number // 编号
  parent: number // 父节点编号
  name: string // 分组名称
  type: number // 类型
  remark: string // 备注
}

// 资源分组树  VO
export interface ResourceGroupTreeVO extends ResourceGroupVO {
  groupChild: ResourceGroupTreeVO[]
}

// 资源分组内容树 VO
export interface ResourceGroupContentTreeVO extends ResourceGroupVO {
  groupChild: ResourceGroupContentTreeVO[]
  contentChild: ResourceContentVO[]
}

export const ResourceGroupApi = {
  // 查询资源分组树
  getResourceGroupTreeList: async (type?: ResourceType) => {
    return await request.get<ResourceGroupTreeVO[]>({
      url: '/resource/group/tree-list',
      params: { type }
    })
  },

  // 创建资源分组
  createResourceGroup: async (data: ResourceGroupVO) => {
    return await request.post({ url: '/resource/group/create', data })
  },

  // 更新资源分组
  updateResourceGroup: async (data: ResourceGroupVO) => {
    return await request.put({ url: '/resource/group/update', data })
  },

  // 获取资源分组
  getResourceGroup: async (id: number) => {
    return await request.get<ResourceGroupVO>({ url: '/resource/group/get?id=' + id })
  },

  // 删除资源分组
  deleteResourceGroup: async (id: number) => {
    return await request.delete({ url: '/resource/group/delete?id=' + id })
  },

  // ==================== 子表（Web3D 资源 内容） ====================
  // 查询资源分组树
  getResourceGroupContentTreeList: async (type?: ResourceType) => {
    return await request.get<ResourceGroupContentTreeVO[]>({
      url: '/resource/group/content/tree-list',
      params: {type}
    })
  },
}
